package com.hyj.dev.tess4j;

import java.awt.BorderLayout;

import org.apache.jmeter.processor.gui.AbstractPostProcessorGui;
import org.apache.jmeter.testelement.TestElement;

public class VcodeExtractorGUI extends AbstractPostProcessorGui{
	private static final long serialVersionUID = 1L;

	private MainPanel mainPanel;
	
	public VcodeExtractorGUI() {
		init(); 
	}
	
	private void init() {
        mainPanel = MainPanel.getInstance();
        setLayout(new BorderLayout(0, 5));
        setBorder(makeBorder());
        add(makeTitlePanel(), BorderLayout.NORTH); // Add the standard title
        add(mainPanel.getPanel(), BorderLayout.CENTER);
	}

	public TestElement createTestElement() {
        VcodeExtractor extractor = new VcodeExtractor();
        modifyTestElement(extractor);
        return extractor;
    }

    public String getLabelResource() {
        return this.getClass().getName();
    }

    @Override
    public String getStaticLabel() {//设置显示名称
        return "验证码识别插件";
    }
    
    /*
     * 把界面的数据移到Sampler中，与configure方法相反
     */
    public void modifyTestElement(TestElement extractor) {
    	extractor.clear();
        super.configureTestElement(extractor);
        
        extractor.setProperty("languagePath", mainPanel.getLanguagePath());
        extractor.setProperty("language", mainPanel.getLanguage());
        extractor.setProperty("captchaType", mainPanel.getCaptchaTypeStr());
        extractor.setProperty("input", mainPanel.getInputText());
        extractor.setProperty("onput", mainPanel.getOnputText());
        
    }
    
    @Override
    public void configure(TestElement element) {

    	mainPanel.setLanguagePath(element.getPropertyAsString("languagePath"));
    	mainPanel.setLanguage(element.getPropertyAsString("language"));
    	mainPanel.setCaptchaType(element.getPropertyAsString("captchaType"));
    	
    	
    	mainPanel.setInputText(element.getPropertyAsString("input"));
    	mainPanel.setOutputText(element.getPropertyAsString("onput"));
    	
    	super.configure(element);
    }
    
    @Override
    public void clearGui() {
    	super.clearGui();
    	mainPanel.reset();
    }
}